package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowedOperation implements IOPeration {
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("输入你要借阅的书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int size = bookList.getUsedSize();
        for (int i = 0; i < size; i++) {
            Book book1 = bookList.getBook(i);
            if (book1.getName().equals(name)) {
                if (book1.getBorrowed()) {
                    System.out.println("该书已经被借阅");
                } else {
                    System.out.println("借阅成功！");
                    book1.setBorrowed(true);
                }
                return;
            }
        }
        System.out.println("你借阅的书籍不存在！");
    }
}